function validate()
{
	if (document.addBillingPlan.name.value == "")
	{
		alert("Please enter a billing plan name.");
		return false;
	}

	if (document.addBillingPlan.baseRate.value == "")
	{
		alert("Please enter a base rate.");
		return false;
	}
	
	var currency = /^\d*\.\d{0,2}$/;
	var currency2 = /^\d+$/;
	if (!currency.test(document.addBillingPlan.baseRate.value) &&
			!currency2.test(document.addBillingPlan.baseRate.value) ||
			document.addBillingPlan.baseRate.value == 0)
	{
		alert("Base rate entered incorrectly.");
		return false;
	}

	// Get the ids of the addedPlans select field
	var addedPlans = document.addBillingPlan.addedPlans.options;
	
	var addedPlanIds = "";
	for (var i = 0; i < addedPlans.length; i++)
	{
		addedPlanIds = addedPlanIds + addedPlans[i].value + ",";
	}
	
	addedPlanIds = addedPlanIds.slice (0, -1);
	document.addBillingPlan.listOfDiscountIds.value = addedPlanIds;
	
	return true;
}

function clearList()
{
	document.addBillingPlan.addedPlans.options.length = 0;
}

function addToList()
{
	var available = document.addBillingPlan.availablePlans;
	var added = document.addBillingPlan.addedPlans;

	for (var i = 0; i < available.options.length; i++)
	{
		if (available.options[i].selected && !checkList(available.options[i].value))
		{
			added.options[added.options.length] = new Option(available.options[i].text, available.options[i].value);
		}

		available.options[i].selected = 0; 
	}
}

function checkList(value)
{
	var found = false;
	var added = document.addBillingPlan.addedPlans;

	for (var i = 0; i < added.options.length; i++)
	{
		if (added.options[i].value == value)
		{
			found = true;
			break;
		}
	}

	return found;
}

function removeFromList()
{
	var added = document.addBillingPlan.addedPlans;

	for (var i = 0; i < added.length; i++)
	{
		if (added.options[i].selected)
		{
			added.options[i] = null;
			i--;
		}
	}
}